package ext.generic.project.reports;

import java.beans.PropertyVetoException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.Vector;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import wt.change2.ChangeHelper2;
import wt.change2.WTChangeIssue;
import wt.change2.WTChangeOrder2;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentHolder;
import wt.content.ContentItem;
import wt.content.ContentRoleType;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.ReferenceFactory;
import wt.fc.WTObject;
import wt.fc.collections.WTCollection;
import wt.inf.team.ContainerTeam;
import wt.inf.team.ContainerTeamHelper;
import wt.inf.team.ContainerTeamManaged;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.org.WTPrincipal;
import wt.org.WTUser;
import wt.part.WTPart;
import wt.project.Role;
import wt.projmgmt.admin.Project2;
import wt.util.WTException;
import wt.util.WTProperties;
import wt.util.WTRuntimeException;
import wt.util.WTStandardDateFormat;

import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.projectmanagement.plan.Plan;
import com.ptc.projectmanagement.plan.PlanActivity;
import com.ptc.projectmanagement.plan.Plannable;
import com.ptc.projectmanagement.plannable.PlannableHelper;
import com.ptc.windchill.history.HistoryRecord;
import com.ptc.windchill.history.HistoryRecordLink;
import com.ptc.windchill.history.HistoryXMLHelper;
import com.ptc.windchill.history.XMLGeneratorHelper;

import ext.com.iba.IBASearchUtil;
import ext.com.iba.IBAUtil;
import ext.com.org.OrgUtil;

public class ProjectReportCommand implements RemoteAccess {

	private static boolean VERBOSE;
	private static String CLASSNAME = ProjectReportCommand.class.getName();
	private static String codebalocation;
	private static WTProperties wtProperties = null;

	static {
		try {
			wtProperties = WTProperties.getLocalProperties();
			VERBOSE = (WTProperties.getLocalProperties()).getProperty("ext.generic.project.reports.verbose", false);
			codebalocation = wtProperties.getProperty("wt.codebase.location", "");
		} catch (Throwable throwable) {
			throw new ExceptionInInitializerError(throwable);
		}
	}

	public ProjectReportCommand() {

	}

	public static ProjectReportCommand newProjectReportCommand() {

		return new ProjectReportCommand();
	}

	/**
	 * 输出调试信息
	 */
	private static void outDebugInfo(String info) {
		if (VERBOSE)
			System.out.println(CLASSNAME + ">>>" + info);
	}

	/**
	 * 
	 * @param findStr
	 * @return
	 * @throws WTException
	 * @throws RemoteException
	 * @throws IOException
	 * @throws Exception
	 */
	public Vector getUserListVector(String findStr) throws WTException, RemoteException, IOException, Exception {
		if (!RemoteMethodServer.ServerFlag) {
			String s4 = "getUserListVector";
			Class aclass[] = { String.class };
			Object aobj[] = { findStr };
			return (Vector) RemoteMethodServer.getDefault().invoke(s4, null, this, aclass, aobj);
		} else {
			Vector projectInfos = ProjectReportUtil.getUserList(findStr);
			return projectInfos;
		}
	}

	/**
	 * 获取可交付结果的齐套性检查报表,jsp页面显示调用
	 * 
	 * @param activity
	 *            活动
	 * @return
	 * @throws WTException
	 */
	public static ArrayList getPhaseReviewDocBean(PlanActivity activity) throws WTException {
		// cb.getPageOid();
		// cb.getPrimaryOid();
		// cb.getActionOid();
		outDebugInfo(CLASSNAME + ".getPhaseReviewDocBean(" + activity + ")");
		if (!RemoteMethodServer.ServerFlag) {
			String methodName = "getPhaseReviewDocBean";
			try {
				return (ArrayList) RemoteMethodServer.getDefault().invoke(methodName, null, CLASSNAME, new Class[] { PlanActivity.class }, new Object[] { activity });
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		ArrayList list = new ArrayList();
		if (activity == null) {
			return list;
		}

		list = ProjectReportUtil.getPhaseReviewDocBean(activity);

		return list;
	}

	/**
	 * 阶段齐套性检查导出成EXCEL xls
	 * 
	 * @param oid
	 *            活动oid
	 * @return 返回excel
	 * @throws FileNotFoundException
	 * @throws IOException
	 * @throws WTException
	 * @throws WTRuntimeException
	 */
	public static HSSFWorkbook getPhaseReviewDocBean(String oid) throws FileNotFoundException, IOException, WTRuntimeException, WTException {
		if (!RemoteMethodServer.ServerFlag) {
			String method = "getPhaseReviewDocBean";
			try {
				HSSFWorkbook xf = (HSSFWorkbook) RemoteMethodServer.getDefault().invoke(method, CLASSNAME, null, new Class[] { String.class }, new Object[] { oid });
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		String filePath = codebalocation + File.separator + "ext" + File.separator + "generic" + File.separator + "project" + File.separator + "reports" + File.separator + "PhaseReviewDocTemplate.xls";
		// 读取excel文件
		File file = new File(filePath);
		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
		HSSFWorkbook hwb = new HSSFWorkbook(fs);
		ReferenceFactory rf = new ReferenceFactory();

		WTObject obj = (WTObject) rf.getReference(oid).getObject();

		if (obj != null && (obj instanceof PlanActivity)) {
			PlanActivity activity = (PlanActivity) obj;
			Plannable planable = activity.getParentPlannable();
			if (!(planable instanceof PlanActivity)) {
				// 非活动节点直接返回
				outDebugInfo("planable  is not instanceof PlanActivity, return null!");
				return hwb;
			}
			PlanActivity parentActivity = (PlanActivity) planable;
			if (parentActivity == null || !parentActivity.isSummary()) {
				outDebugInfo("parentActivity==null||!parentActivity.isSummary()");
				return hwb;
			}

			outDebugInfo(">>>activity>>>:" + activity.getName() + " parent is " + parentActivity.getName() + " is isSummary=" + parentActivity.isSummary());
			ProjectReportUtil.getPhaseReviewDocBeanWriteToExcel(hwb, parentActivity);
		}

		return hwb;
	}

	/**
	 * 通过项目名称、项目状态、项目经理、预估开始时间、预估结束时间等条件查询符合以上条件的项目，以报表形式导出项目的里程碑活动
	 * 
	 * @param projectName
	 *            项目名称
	 * @param projectState
	 *            项目状态
	 * @param startDate
	 *            开始时间
	 * @param endDate
	 *            结束时间
	 * @param commandBean
	 *            包含picker的对象
	 * @return
	 * @throws FileNotFoundException
	 * @throws IOException
	 * @throws WTRuntimeException
	 * @throws WTException
	 */
	public static HSSFWorkbook getMileStoneReports(String projectName, String projectState, String startDate, String endDate, NmCommandBean commandBean) throws FileNotFoundException, IOException, WTRuntimeException, WTException {
		outDebugInfo(CLASSNAME + ".getMileStoneReports()");
		if (!RemoteMethodServer.ServerFlag) {
			String method = "getMileStoneReports";
			try {
				HSSFWorkbook hwb = (HSSFWorkbook) RemoteMethodServer.getDefault().invoke(method, CLASSNAME, null, new Class[] { String.class, String.class, String.class, String.class, NmCommandBean.class },
						new Object[] { projectName, projectState, startDate, endDate, commandBean });
				return hwb;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		String filePath = codebalocation + File.separator + "ext" + File.separator + "generic" + File.separator + "project" + File.separator + "reports" + File.separator + "mileStoneReportsTemplate.xls";
		// 读取excel文件
		File file = new File(filePath);
		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
		HSSFWorkbook hwb = new HSSFWorkbook(fs);
		HSSFSheet sheet = hwb.getSheetAt(0);

		outDebugInfo("commandBean.getTextParameter()>>>>>" + commandBean.getTextParameter("userPicker"));
		String uid = commandBean.getTextParameter("userPicker");
		WTUser user = null;
		String userId = "";
		if (uid != null && !"".equals(uid)) {
			String[] str = uid.split(",");
			String temp = str[0];
			if (VERBOSE) {
				System.out.println("======>>>temp>>>>:" + temp);
			}
			str = temp.split("=");
			userId = str[1];
			if (VERBOSE) {
				System.out.println("======>>>userId>>>>:" + userId);
			}
			user = OrgUtil.getUserById(userId);
			System.out.println("user.getName>>>>>" + user.getName());
		}
		// WTUser user = (WTUser) principal;
		// WTUser user =
		// OrganizationServicesHelper.manager.getUser(commandBean.getTextParameter("userPicker"));

		// System.out.println("userName>>>>"+user.getName());
		outDebugInfo("projectName>>>>>" + projectName);
		outDebugInfo("projectState>>>>>" + projectState);
		outDebugInfo("startDate>>>>>" + startDate);
		outDebugInfo("endDate>>>>>" + endDate);
		Date startDate1 = null;
		Date endDate1 = null;
		SimpleDateFormat f = new SimpleDateFormat("yyyy/MM/dd"); // 格式化为
		// hhmmss
		try {
			startDate1 = f.parse(startDate);

			endDate1 = f.parse(endDate);
		} catch (ParseException e) {
			SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM-dd"); // 格式化为
			// hhmmss
			try {
				startDate1 = f2.parse(startDate);
				endDate1 = f2.parse(endDate);
			} catch (ParseException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
		Vector<Project2> verProj = new Vector<Project2>();
		QueryResult qr = TianmaProjectUtil.queryProjectForMileStoneReport(projectName, startDate1, endDate1);
		outDebugInfo("qr.size()>>>" + qr.size());

		if (qr.size() > 0) {
			while (qr.hasMoreElements()) {
				Project2 proj = (Project2) qr.nextElement();
				String state = proj.getContainerTeamManagedInfo().getState().toString();
				if (!"All".equals(projectState)) {
					if (!(projectState.equals(state))) {
						outDebugInfo("projectState:" + projectState + ">>>state:" + state);
						continue;
					}
				}

				if (proj != null) {

					ContainerTeam containerTeam = ContainerTeamHelper.service.getContainerTeam((ContainerTeamManaged) proj);
					Role role = Role.toRole("PROJECT MANAGER");
					ArrayList prinList = containerTeam.getAllPrincipalsForTarget(role);
					outDebugInfo("prinList:" + prinList.size());
					for (int w = 0; w < prinList.size(); w++) {
						WTPrincipal pr = ((wt.org.WTPrincipalReference) prinList.get(w)).getPrincipal();
						outDebugInfo("pr:" + pr.getName());
						if (pr instanceof WTUser) {
							WTUser userTemp = (WTUser) pr;
							if (user == null) {
								outDebugInfo("*****select user is null*****");
								if(!verProj.contains(proj)){
									outDebugInfo("the vector not contains the project:"+proj.getName()+" need put in it");
									verProj.add(proj);
								}
								
							} else {
								if (userTemp.getFullName().equals(user.getFullName())) {
									outDebugInfo("userTemp.getFullName().equals(user.getFullName()) is true");
									outDebugInfo("userName:"+user.getFullName());
									if(!verProj.contains(proj)){
										outDebugInfo("the vector not contains the project:"+proj.getName()+" need put in it");
										verProj.add(proj);
									}
									
								}
							}

						}/*
						 * else if(pr instanceof WTGroup){
						 * TianmaProjectUtil.addUser(participants, wtp) }
						 */
					}

				}
			}
		}
		HSSFRow row = null;
		HSSFCell cell = null;
		int i = 0;
		outDebugInfo("verProj.size()>>>"+verProj.size());
		for (int k = 0; k < verProj.size(); k++) {
			Project2 proj = verProj.get(k);
			Plan plan = TianmaProjectUtil.getPlan(proj);
			if (plan == null) {
				continue;
			}

			WTCollection wtc = PlannableHelper.service.getAllChildren((Plannable) plan);
			Iterator itor = wtc.persistableIterator();
			// HashMap map = new HashMap();
			int cellY = 0;// 列
			boolean flag = false;// 项目活动有里程碑
			if (itor.hasNext()) {
				while (itor.hasNext()) {
					PlanActivity planActi = (PlanActivity) itor.next();
					if (planActi != null) {
						// 非里程碑 不做处理
						if (!planActi.isMilestone()) {
							continue;
						}
						// 计划根节点不做处理
						if (planActi.getLineNumber() == 0) {
							continue;
						}
						// 预计完成时间
						outDebugInfo(proj.getName()+">>>planActi.getName()>>>"+planActi.getName() + ">>>>planActi.isMilestone()" + planActi.isMilestone());
						Timestamp esCompTime = planActi.getFinishDate();
						String esCompTimeStr = "";
						if (esCompTime != null) {
							esCompTime.setHours(esCompTime.getHours() + 8);
							esCompTimeStr = WTStandardDateFormat.format(esCompTime, "yyyy/MM/dd");
						}
						// map.put(planActi.getName(), esCompTimeStr);

						if (cellY == 0) {
							outDebugInfo("row>>>" + (i + 1) + ">>>cellY:" + cellY);
							row = sheet.getRow(i + 1);
							cell = row.getCell(cellY);
							cell.setCellValue(proj.getName());
							cellY++;

						}
						row = sheet.getRow(i);
						// 活动名称
						cell = row.getCell(cellY);
						cell.setCellValue(planActi.getName());
						outDebugInfo("row>>>" + i + ">>>cellY:" + cellY);
						// 样式设置
						// cell = row.getCell(cellY);
						/*
						 * HSSFCellStyle cs = hwb.createCellStyle();
						 * cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
						 * cs.setFillForegroundColor(new
						 * HSSFColor.GREEN().getIndex()); cell.setCellStyle(cs);
						 */

						row = sheet.getRow(i + 1);
						// 预计完成时间
						cell = row.getCell(cellY);
						cell.setCellValue(esCompTimeStr);
						outDebugInfo("row>>>" + i + ">>>cellY:" + cellY);
						cellY++;
						flag = true;

					}
				}
				if (flag) {
					i = i + 3;
				}

			}

		}

		return hwb;
	}

	/**
	 * 里程碑变更报表输出方法入口
	 * @param projectOID
	 * @return
	 * @throws FileNotFoundException
	 * @throws IOException
	 * @throws WTRuntimeException
	 * @throws WTException
	 */
	public static HSSFWorkbook getProjectMileStoneChangeListReport(String reportType,String projectOID,NmCommandBean commandBean) throws FileNotFoundException, IOException, WTRuntimeException{
		outDebugInfo(CLASSNAME + ".getProjectMileStoneChangeListReport("+projectOID+")");
		System.out.println(">>>"+!RemoteMethodServer.ServerFlag);
		if (!RemoteMethodServer.ServerFlag) {
			System.out.println(">>>"+!RemoteMethodServer.ServerFlag);
			String method = "getProjectMileStoneChangeListReport";
			try {
				HSSFWorkbook hwb = (HSSFWorkbook) RemoteMethodServer.getDefault().invoke(method, CLASSNAME, null, new Class[] { String.class,String.class,NmCommandBean.class},
						new Object[] {reportType, projectOID,commandBean });
				return hwb;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		Project2 proj=null;
		ReferenceFactory rff=new ReferenceFactory();
		try{
		
			proj=(Project2) rff.getReference(projectOID).getObject();
		}catch (WTException e) {
			// TODO: handle exception
		}
		
		if(proj==null){
			try {
				proj=(Project2) commandBean.getContainer();
			} catch (WTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		String filePath ="";
		HSSFWorkbook hwb;
		//问题报告列表
		if("IssueListReport".equals(reportType)){
			outDebugInfo("reportType>>>"+reportType);
			filePath = codebalocation + File.separator + "ext" + File.separator + "generic" + File.separator + "project" + File.separator + "reports" + File.separator + "mileStoneIssueListReportTemplate.xls";
			File file = new File(filePath);
			POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
			 hwb = new HSSFWorkbook(fs);
			 try {
				getChangeIssueListReport(proj, hwb);
			} catch (WTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if("ChangesListReport".equals(reportType)){
			//ECN
			filePath = codebalocation + File.separator + "ext" + File.separator + "generic" + File.separator + "project" + File.separator + "reports" + File.separator + "mileStoneChange_ECN_ReportsTemplate.xls";
			File file = new File(filePath);
			POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
			 hwb = new HSSFWorkbook(fs);
			 try {
				getMileStoneChange_ECN_ListReport(proj, hwb);
			} catch (WTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (PropertyVetoException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}else {
			//里程碑变更
			//MileStoneChangeListReport
			filePath = codebalocation + File.separator + "ext" + File.separator + "generic" + File.separator + "project" + File.separator + "reports" + File.separator + "mileStoneReportsTemplate.xls";
			File file = new File(filePath);
			POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
			 hwb = new HSSFWorkbook(fs);
			 try {
				getMileStoneChangeListReport(proj, hwb);
			} catch (WTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		outDebugInfo("write hwb end");
		
		
		
		return hwb;
	}
	
	/**
	 * 获取项目中的问题报告记录信息
	 * @param proj
	 * @param hwb
	 * @throws RemoteException
	 * @throws WTException
	 */
	public static void getChangeIssueListReport(Project2 proj,HSSFWorkbook hwb) throws RemoteException, WTException{
		// 读取excel文件
		HSSFSheet sheet = hwb.getSheetAt(0);
		HSSFRow row = null;
		HSSFCell cell = null;
		int i = 1;
		QueryResult qr=TianmaProjectUtil.queryPRWithContiner(proj);
		outDebugInfo("qr.size()>>>"+qr.size());
		if(qr!=null){
			while(qr.hasMoreElements()){
				Persistable[] pb=(Persistable[]) qr.nextElement();
				
				//System.out.println(pb[0]);
				WTChangeIssue issue=(WTChangeIssue) pb[0];
				outDebugInfo("issue:>>>"+issue);
				//WTChangeIssueMaster issueMaster=(WTChangeIssueMaster) issue.getMaster();
				
				//问题状态
				String prState=IBAUtil.getIBAValue(issue, "PRState")==null?"":IBAUtil.getIBAValue(issue, "PRState").toString();
				outDebugInfo("prState:>>>"+prState);
				//严重程度
				String severityLevel=IBAUtil.getIBAValue(issue, "SeverityLevel")==null?"":IBAUtil.getIBAValue(issue, "SeverityLevel").toString();
				outDebugInfo("severityLevel:>>>"+severityLevel);
				
				//TrialProduceNumber 试制号
				String trialProduceNumber=IBAUtil.getIBAValue(issue, "TrialProduceNumber")==null?"":IBAUtil.getIBAValue(issue, "TrialProduceNumber").toString();
				outDebugInfo("trialProduceNumber:>>>"+trialProduceNumber);
				//PRSource 问题来源
				String prSource=IBAUtil.getIBAValue(issue, "PRSource")==null?"":IBAUtil.getIBAValue(issue, "PRSource").toString();
				outDebugInfo("prSource:>>>"+prSource);
				
				// OutcomeConfirmation 效果确认
				String outcomeConfirmation=IBAUtil.getIBAValue(issue, "OutcomeConfirmation")==null?"":IBAUtil.getIBAValue(issue, "OutcomeConfirmation").toString();
				outDebugInfo("outcomeConfirmation:>>>"+outcomeConfirmation);
				//产品型号
				String productType=proj.getName();
				outDebugInfo("productType:>>>"+productType);
				//提出时间:
				Timestamp icreateTime=issue.getCreateTimestamp();
				String createTime="";
				if(icreateTime!=null){
					icreateTime.setHours(icreateTime.getHours()+8);
					createTime= WTStandardDateFormat.format(icreateTime,"yyyy/MM/dd");
				}
				outDebugInfo("createTime:>>>"+createTime);
				//问题描述
				String desc=issue.getDescription();
				outDebugInfo("desc:>>>"+desc);
				//创建者
				String creator=issue.getCreator().getDisplayName();
				outDebugInfo("creator:>>>"+creator);
				//解决日期
				Timestamp solutionDate=issue.getResolutionDate();
				
				String solutionTime="";
				if(solutionDate!=null){
					solutionDate.setHours(solutionDate.getHours()+8);
					solutionTime= WTStandardDateFormat.format(solutionDate,"yyyy/MM/dd");
				}
				outDebugInfo("solutionTime:>>>"+solutionTime);
				
				//产品型号
				row = sheet.getRow(i);
				cell = row.getCell(0);
				cell.setCellValue(productType);
				outDebugInfo("0:>>>"+productType);
				
				//问题状态
				cell = row.getCell(1);
				cell.setCellValue(prState);
				outDebugInfo("1:>>>"+prState);
				
				//严重程度
				cell = row.getCell(2);
				cell.setCellValue(severityLevel);
				outDebugInfo("2:>>>"+severityLevel);
				
				//提出时间
				cell = row.getCell(3);
				cell.setCellValue(createTime);
				outDebugInfo("3:>>>"+createTime);
				
				//试制号
				cell = row.getCell(4);
				cell.setCellValue(trialProduceNumber);
				outDebugInfo("4:>>>"+trialProduceNumber);
				
				
				//问题来源
				cell = row.getCell(5);
				cell.setCellValue(prSource);
				outDebugInfo("5:>>>"+prSource);
				
				//问题描述
				cell = row.getCell(6);
				cell.setCellValue(desc);
				outDebugInfo("6:>>>"+desc);
				
				//问题负责人
				cell = row.getCell(7);
				cell.setCellValue(creator);
				outDebugInfo("7:>>>"+creator);
				
				//关闭日期
				cell = row.getCell(8);
				cell.setCellValue(solutionTime);
				outDebugInfo("8:>>>"+solutionTime);
				
				//效果确认
				cell = row.getCell(9);
				cell.setCellValue(outcomeConfirmation);
				outDebugInfo("9:>>>"+outcomeConfirmation);
				i++;
				
				
			}
		}
		//return hwb;
	}

	/**
	 * 根据ECN的IBA属性‘受影响的成品’的值为‘项目名称’，获取相关的ECN的报表
	 * @param proj 项目
	 * @param hwb
	 * @throws WTException 
	 * @throws PropertyVetoException 
	 * @throws IOException 
	 */
	public static void getMileStoneChange_ECN_ListReport(Project2 proj,HSSFWorkbook hwb) throws WTException, PropertyVetoException, IOException{
		// 读取excel文件
		HSSFSheet sheet = hwb.getSheetAt(0);
		String projectName="";
		if(proj!=null){
			projectName=proj.getName();
		}
		String ibaName="AffectedProducts";//受影响的成品
		//QueryResult qr=IBASearchUtil.filterByAttributeValue(WTChangeOrder2.class, ibaName, projectName);
		Hashtable ibaValues=new Hashtable();
		ibaValues.put(ibaName, projectName);
		
		QueryResult qr=IBASearchUtil.queryIBAHolder(WTChangeOrder2.class, ibaValues);
		outDebugInfo("getChangesListReport>>> with IBA='AffectedProducts' and the value="+projectName+" ,return size="+qr.size());
		HSSFRow row = null;
		HSSFCell cell = null;
		int i = 1;
		while(qr.hasMoreElements()){
			WTChangeOrder2 ecn=(WTChangeOrder2) qr.nextElement();
			outDebugInfo("ECN:"+ecn.getName());
			//变更类型 ChangeType
			String changeType=IBAUtil.getIBAValue(ecn, "ChangeType")==null?"":IBAUtil.getIBAValue(ecn, "ChangeType").toString();
			row = sheet.getRow(i);
			cell = row.getCell(0);
			cell.setCellValue(changeType);
			
			//产品阶段 ProductStage
			String productStage=IBAUtil.getIBAValue(ecn, "ProductStage")==null?"":IBAUtil.getIBAValue(ecn, "ProductStage").toString();
			cell = row.getCell(1);
			cell.setCellValue(productStage);
			
			//产品维度finishedGoodDimension
			String finishedGoodDimension=IBAUtil.getIBAValue(ecn, "finishedGoodDimension")==null?"":IBAUtil.getIBAValue(ecn, "finishedGoodDimension").toString();
			cell = row.getCell(2);
			cell.setCellValue(finishedGoodDimension);
			//成品研发地 RDArea
			String RDArea=IBAUtil.getIBAValue(ecn, "RDArea")==null?"":IBAUtil.getIBAValue(ecn, "RDArea").toString();
			cell = row.getCell(3);
			cell.setCellValue(RDArea);
			//变更来源 ChangeSource
			String ChangeSource=IBAUtil.getIBAValue(ecn, "ChangeSource")==null?"":IBAUtil.getIBAValue(ecn, "ChangeSource").toString();
			cell = row.getCell(4);
			cell.setCellValue(ChangeSource);
			//变更分类 ChangeCategory
			String ChangeCategory=IBAUtil.getIBAValue(ecn, "ChangeCategory")==null?"":IBAUtil.getIBAValue(ecn, "ChangeCategory").toString();
			cell = row.getCell(5);
			cell.setCellValue(ChangeCategory);
			//变更原因细化ChangeReasonRefinement
			String ChangeReasonRefinement=IBAUtil.getIBAValue(ecn, "ChangeReasonRefinement")==null?"":IBAUtil.getIBAValue(ecn, "ChangeReasonRefinement").toString();
			cell = row.getCell(6);
			cell.setCellValue(ChangeReasonRefinement);
			//详细变更原因说明DetailedReasonsForChanges
			String DetailedReasonsForChanges=IBAUtil.getIBAValue(ecn, "DetailedReasonsForChanges")==null?"":IBAUtil.getIBAValue(ecn, "DetailedReasonsForChanges").toString();
			cell = row.getCell(7);
			cell.setCellValue(DetailedReasonsForChanges);
			//生产地 Production
			String Production=IBAUtil.getIBAValue(ecn, "Production")==null?"":IBAUtil.getIBAValue(ecn, "Production").toString();
			cell = row.getCell(8);
			cell.setCellValue(Production);
			//变更后AfterTheChange
			String AfterTheChange=IBAUtil.getIBAValue(ecn, "AfterTheChange")==null?"":IBAUtil.getIBAValue(ecn, "AfterTheChange").toString();
			cell = row.getCell(9);
			cell.setCellValue(AfterTheChange);
			//****************************项目信息（深圳） ******************begin
			//是否更改模具ChangeMould
			String ChangeMould=IBAUtil.getIBAValue(ecn, "ChangeMould")==null?"":IBAUtil.getIBAValue(ecn, "ChangeMould").toString();
			cell = row.getCell(10);
			cell.setCellValue(ChangeMould);
			//模具类型 TypeOfMold
			String mouldtype=IBAUtil.getIBAValue(ecn, "TypeOfMold")==null?"":IBAUtil.getIBAValue(ecn, "TypeOfMold").toString();
			cell = row.getCell(11);
			cell.setCellValue(mouldtype);
			//可能带来新EHS风险IsNewEHS
			String IsNewEHS=IBAUtil.getIBAValue(ecn, "IsNewEHS")==null?"":IBAUtil.getIBAValue(ecn, "IsNewEHS").toString();
			cell = row.getCell(12);
			cell.setCellValue(IsNewEHS);
			//需索取或更新环保报告IsNeedReport
			String IsNeedReport=IBAUtil.getIBAValue(ecn, "IsNeedReport")==null?"":IBAUtil.getIBAValue(ecn, "IsNeedReport").toString();
			cell = row.getCell(13);
			cell.setCellValue(IsNeedReport);
			//报价员Declarant
			String Declarant=IBAUtil.getIBAValue(ecn, "Declarant")==null?"":IBAUtil.getIBAValue(ecn, "Declarant").toString();
			cell = row.getCell(14);
			cell.setCellValue(Declarant);
			//业务员Parlor
			String Parlor=IBAUtil.getIBAValue(ecn, "Parlor")==null?"":IBAUtil.getIBAValue(ecn, "Parlor").toString();
			cell = row.getCell(15);
			cell.setCellValue(Parlor);
			//变更产生模费MouldCost
			String MouldCost=IBAUtil.getIBAValue(ecn, "MouldCost")==null?"":IBAUtil.getIBAValue(ecn, "MouldCost").toString();
			cell = row.getCell(16);
			cell.setCellValue(MouldCost);
			//收取客户模费NeedCusCost
			String NeedCusCost=IBAUtil.getIBAValue(ecn, "NeedCusCost")==null?"":IBAUtil.getIBAValue(ecn, "NeedCusCost").toString();
			cell = row.getCell(17);
			cell.setCellValue(NeedCusCost);
			//****************************项目信息（深圳） ******************end
			//风险评估RiskAssessment
			String RiskAssessment=IBAUtil.getIBAValue(ecn, "RiskAssessment")==null?"":IBAUtil.getIBAValue(ecn, "RiskAssessment").toString();
			cell = row.getCell(18);
			cell.setCellValue(RiskAssessment);
			//********************************功能影响*******************************begin
			//功能影响ACD深圳LCD设计  FunctionACDSZ
			String FunctionACDSZ=IBAUtil.getIBAValue(ecn, "FunctionACDSZ")==null?"":IBAUtil.getIBAValue(ecn, "FunctionACDSZ").toString();
			cell = row.getCell(19);
			cell.setCellValue(FunctionACDSZ);
			
			//ACD/深圳LCD设计意见  ACDSZOther
			String ACDSZOther=IBAUtil.getIBAValue(ecn, "ACDSZOther")==null?"":IBAUtil.getIBAValue(ecn, "ACDSZOther").toString();
			cell = row.getCell(20);
			cell.setCellValue(ACDSZOther);
			
			//功能影响:OD/深圳PM  FunctionODSZ
			String FunctionODSZ=IBAUtil.getIBAValue(ecn, "FunctionODSZ")==null?"":IBAUtil.getIBAValue(ecn, "FunctionODSZ").toString();
			cell = row.getCell(21);
			cell.setCellValue(FunctionODSZ);
			
			//OD深圳PM意见    ODSZOther
			String ODSZOther=IBAUtil.getIBAValue(ecn, "ODSZOther")==null?"":IBAUtil.getIBAValue(ecn, "ODSZOther").toString();
			cell = row.getCell(22);
			cell.setCellValue(ODSZOther);
			
			//功能影响：Layout/深圳LCM布线       FunctionLayoutSZ
			String FunctionLayoutSZ=IBAUtil.getIBAValue(ecn, "FunctionLayoutSZ")==null?"":IBAUtil.getIBAValue(ecn, "FunctionLayoutSZ").toString();
			cell = row.getCell(23);
			cell.setCellValue(FunctionLayoutSZ);
			
			//Layout深圳LCM布线意见   LayoutSZOther
			String LayoutSZOther=IBAUtil.getIBAValue(ecn, "LayoutSZOther")==null?"":IBAUtil.getIBAValue(ecn, "LayoutSZOther").toString();
			cell = row.getCell(24);
			cell.setCellValue(LayoutSZOther);
			
			//功能影响：ME/深圳PM   FunctionMESZ
			String FunctionMESZ=IBAUtil.getIBAValue(ecn, "FunctionMESZ")==null?"":IBAUtil.getIBAValue(ecn, "FunctionMESZ").toString();
			cell = row.getCell(25);
			cell.setCellValue(FunctionMESZ);
			
			//ME深圳PM意见    MESZOther
			String MESZOther=IBAUtil.getIBAValue(ecn, "MESZOther")==null?"":IBAUtil.getIBAValue(ecn, "MESZOther").toString();
			cell = row.getCell(26);
			cell.setCellValue(MESZOther);
			
			//功能影响EE深圳PM   FunctionEESZ
			String FunctionEESZ=IBAUtil.getIBAValue(ecn, "FunctionEESZ")==null?"":IBAUtil.getIBAValue(ecn, "FunctionEESZ").toString();
			cell = row.getCell(27);
			cell.setCellValue(FunctionEESZ);
			
			//EE深圳PM意见   EESZOther
			String EESZOther=IBAUtil.getIBAValue(ecn, "EESZOther")==null?"":IBAUtil.getIBAValue(ecn, "EESZOther").toString();
			cell = row.getCell(28);
			cell.setCellValue(EESZOther);
			//********************************功能影响*******************************end
			
			//********************************良率*******************************begin
			//良率影响:Array/深圳LCM一厂    LArray
			String LArray=IBAUtil.getIBAValue(ecn, "LArray")==null?"":IBAUtil.getIBAValue(ecn, "LArray").toString();
			cell = row.getCell(29);
			cell.setCellValue(LArray);
			
			//Array/深圳LCM一厂意见:      LArrayOther
			String LArrayOther=IBAUtil.getIBAValue(ecn, "LArrayOther")==null?"":IBAUtil.getIBAValue(ecn, "LArrayOther").toString();
			cell = row.getCell(30);
			cell.setCellValue(LArrayOther);
			
			//良率影响:Cell/深圳LCM五厂     LCell
			String LCell=IBAUtil.getIBAValue(ecn, "LCell")==null?"":IBAUtil.getIBAValue(ecn, "LCell").toString();
			cell = row.getCell(31);
			cell.setCellValue(LCell);
			
			//Cell/深圳LCM五厂意见             LCellOther
			String LCellOther=IBAUtil.getIBAValue(ecn, "LCellOther")==null?"":IBAUtil.getIBAValue(ecn, "LCellOther").toString();
			cell = row.getCell(32);
			cell.setCellValue(LCellOther);
			
			//良率影响:Module/深圳CTP厂   LModule
			String LModule=IBAUtil.getIBAValue(ecn, "LModule")==null?"":IBAUtil.getIBAValue(ecn, "LModule").toString();
			cell = row.getCell(33);
			cell.setCellValue(LModule);
			
			//Module/深圳CTP厂意见            LModuleOther
			String LModuleOther=IBAUtil.getIBAValue(ecn, "LModuleOther")==null?"":IBAUtil.getIBAValue(ecn, "LModuleOther").toString();
			cell = row.getCell(34);
			cell.setCellValue(LModuleOther);
			
			//良率影响:PI/深圳车机厂         LPL
			String LPL=IBAUtil.getIBAValue(ecn, "LPL")==null?"":IBAUtil.getIBAValue(ecn, "LPL").toString();
			cell = row.getCell(35);
			cell.setCellValue(LPL);
			
			//PI/深圳车机厂意见                 LPLOther
			String LPLOther=IBAUtil.getIBAValue(ecn, "LPLOther")==null?"":IBAUtil.getIBAValue(ecn, "LPLOther").toString();
			cell = row.getCell(36);
			cell.setCellValue(LPLOther);
			
			//良率影响:CF/深圳CSTN厂         LCF
			String LCF=IBAUtil.getIBAValue(ecn, "LCF")==null?"":IBAUtil.getIBAValue(ecn, "LCF").toString();
			cell = row.getCell(37);
			cell.setCellValue(LCF);
			
			//CF深圳CSTN厂意见                   LCFOther
			String LCFOther=IBAUtil.getIBAValue(ecn, "LCFOther")==null?"":IBAUtil.getIBAValue(ecn, "LCFOther").toString();
			cell = row.getCell(38);
			cell.setCellValue(LCFOther);
			//********************************良率*******************************end
			
			//品质影响Quality
			String quality=IBAUtil.getIBAValue(ecn, "Quality")==null?"":IBAUtil.getIBAValue(ecn, "Quality").toString();
			cell = row.getCell(39);
			cell.setCellValue(quality);
			//BOM评估BOMReview
			String bomReview=IBAUtil.getIBAValue(ecn, "BOMReview")==null?"":IBAUtil.getIBAValue(ecn, "BOMReview").toString();
			cell = row.getCell(40);
			cell.setCellValue(bomReview);
			//是否送样sendSamples
			String sendSamples=IBAUtil.getIBAValue(ecn, "sendSamples")==null?"":IBAUtil.getIBAValue(ecn, "sendSamples").toString();
			cell = row.getCell(41);
			cell.setCellValue(sendSamples);
			//是否通知客户NoticeCus
			String NoticeCus=IBAUtil.getIBAValue(ecn, "NoticeCus")==null?"":IBAUtil.getIBAValue(ecn, "NoticeCus").toString();
			cell = row.getCell(42);
			cell.setCellValue(NoticeCus);
			
			//*******************************ECN标准属性*********************begin
			//相关产品    容器名称
			//String ChangeSource=IBAUtil.getIBAValue(ecn, "ChangeSource")==null?"":IBAUtil.getIBAValue(ecn, "ChangeSource").toString();
			cell = row.getCell(43);
			cell.setCellValue(ecn.getContainerName());
			
			//ECN编号
			//String ChangeSource=IBAUtil.getIBAValue(ecn, "ChangeSource")==null?"":IBAUtil.getIBAValue(ecn, "ChangeSource").toString();
			cell = row.getCell(44);
			cell.setCellValue(ecn.getNumber());
			
			//ECN名称
			//String ChangeSource=IBAUtil.getIBAValue(ecn, "ChangeSource")==null?"":IBAUtil.getIBAValue(ecn, "ChangeSource").toString();
			cell = row.getCell(45);
			cell.setCellValue(ecn.getName());
			
			//ECN说明
			//String ChangeSource=IBAUtil.getIBAValue(ecn, "ChangeSource")==null?"":IBAUtil.getIBAValue(ecn, "ChangeSource").toString();
			cell = row.getCell(46);
			cell.setCellValue(ecn.getDescription());
			
			//受影响的对象
			Vector beforeVector=new Vector();
			TianmaProjectUtil.getChangeablesBefore(ecn, beforeVector);
			cell = row.getCell(47);
			cell.setCellValue(TianmaProjectUtil.getVectorsName(beforeVector));
			
			//受影响的成品
			Vector<WTPart> vecPart=TianmaProjectUtil.getProductOfECN(ecn);
			cell = row.getCell(48);
			cell.setCellValue(TianmaProjectUtil.getVectorsName(vecPart));
			
			//产生的对象
			Vector afterVector=new Vector();
			TianmaProjectUtil.getChangeablesAfter(ecn, afterVector);
			cell = row.getCell(49);
			cell.setCellValue(TianmaProjectUtil.getVectorsName(afterVector));
			
			//需要日期
			Timestamp ecnNeedDate=ecn.getNeedDate();
			String ecnNeedTime="";
			if(ecnNeedDate!=null){
				ecnNeedDate.setHours(ecnNeedDate.getHours()+8);
				ecnNeedTime= WTStandardDateFormat.format(ecnNeedDate,"yyyy/MM/dd");
			}
			outDebugInfo("ecnNeedTime:>>>"+ecnNeedTime);
			cell = row.getCell(50);
			cell.setCellValue(ecnNeedTime);
			
			//附件
			StringBuffer contentNamesBuffer=new StringBuffer();
			ContentHolder contentHolder = (ContentHolder)ecn;
	    	contentHolder = ContentHelper.service.getContents(contentHolder);
	    	Vector contentListAllVc = ContentHelper.getContentListAll(contentHolder);
	    	for(int kk=0;kk<contentListAllVc.size();kk++)
			{
				ContentItem item = (ContentItem) contentListAllVc.elementAt(kk);
				ContentRoleType roleType = item.getRole();
				if(item instanceof ApplicationData)
				{
					 if(roleType.equals(ContentRoleType.SECONDARY))
					{
						ApplicationData data = (ApplicationData)item;
						if(contentNamesBuffer.toString().equals("")){
							contentNamesBuffer.append(data.getFileName());
						}else{
							contentNamesBuffer.append(";").append(data.getFileName());
						}
					}
				}
			}
			cell = row.getCell(51);
			cell.setCellValue(contentNamesBuffer.toString());
			
			
			//实施计划
			Vector vecECA=ChangeHelper2.service.getChangeActivities(ecn).getObjectVector().getVector();
			cell = row.getCell(52);
			cell.setCellValue(TianmaProjectUtil.getVectorsName(vecECA));
			
			//创建方 创建人员
			String ecnCreator=ecn.getCreatorFullName()==null?"":ecn.getCreatorFullName();
			cell = row.getCell(53);
			cell.setCellValue(ecnCreator);
			
			//已创建   变更通知单的创建时间
			Timestamp ecnCreateDate=ecn.getCreateTimestamp();
			String ecnCreateTime="";
			if(ecnCreateDate!=null){
				ecnCreateDate.setHours(ecnCreateDate.getHours()+8);
				ecnCreateTime= WTStandardDateFormat.format(ecnCreateDate,"yyyy/MM/dd");
			}
			outDebugInfo("ecnCreateTime:>>>"+ecnCreateTime);
			cell = row.getCell(54);
			cell.setCellValue(ecnCreateTime);
			
			//已提交  变更通知单的提交时间
			//String ChangeSource=IBAUtil.getIBAValue(ecn, "ChangeSource")==null?"":IBAUtil.getIBAValue(ecn, "ChangeSource").toString();
			cell = row.getCell(55);
			cell.setCellValue(ecnCreateTime);
			
			//上次修改    变更通知单最近一次修改的时间
			Timestamp ecnModifyDate=ecn.getModifyTimestamp();
			String ecnModifyTime="";
			if(ecnModifyDate!=null){
				ecnModifyDate.setHours(ecnModifyDate.getHours()+8);
				ecnModifyTime= WTStandardDateFormat.format(ecnModifyDate,"yyyy/MM/dd");
			}
			cell = row.getCell(56);
			cell.setCellValue(ecnModifyTime);
			
			//状态   变更通知单的生命周期状态
			String state=ecn.getLifeCycleState().getDisplay();
			cell = row.getCell(57);
			cell.setCellValue(state);
			//*******************************ECN标准属性*********************end
			
			//变更通知客制化属性***********************
			//受影响的成品  AffectedProducts
			String AffectedProducts=IBAUtil.getIBAValue(ecn, "AffectedProducts")==null?"":IBAUtil.getIBAValue(ecn, "AffectedProducts").toString();
			cell = row.getCell(58);
			cell.setCellValue(AffectedProducts);
			
			//是否衍生其他项目变更 OtherProjectChange
			String OtherProjectChange=IBAUtil.getIBAValue(ecn, "OtherProjectChange")==null?"":IBAUtil.getIBAValue(ecn, "OtherProjectChange").toString();
			cell = row.getCell(59);
			cell.setCellValue(OtherProjectChange);
			//*******************************功能验证结果*********************begin
			
			//ACD/深圳LCD设计   FACD
			String FACD=IBAUtil.getIBAValue(ecn, "FACD")==null?"":IBAUtil.getIBAValue(ecn, "FACD").toString();
			cell = row.getCell(60);
			cell.setCellValue(FACD);
			
			//ACD深圳LCD设计意见   FACDOther
			String FACDOther=IBAUtil.getIBAValue(ecn, "FACDOther")==null?"":IBAUtil.getIBAValue(ecn, "FACDOther").toString();
			cell = row.getCell(61);
			cell.setCellValue(FACDOther);
			
			//功能OD深圳PM   FOD
			String FOD=IBAUtil.getIBAValue(ecn, "FOD")==null?"":IBAUtil.getIBAValue(ecn, "FOD").toString();
			cell = row.getCell(62);
			cell.setCellValue(FOD);
			
			//OD深圳PM意见   FODOther
			String FODOther=IBAUtil.getIBAValue(ecn, "FODOther")==null?"":IBAUtil.getIBAValue(ecn, "FODOther").toString();
			cell = row.getCell(63);
			cell.setCellValue(FODOther);
			
			//Layout/深圳LCM布线   FLayout
			String FLayout=IBAUtil.getIBAValue(ecn, "FLayout")==null?"":IBAUtil.getIBAValue(ecn, "FLayout").toString();
			cell = row.getCell(64);
			cell.setCellValue(FLayout);
			
			//Layout/深圳LCM布线意见  FLayoutOther
			String FLayoutOther=IBAUtil.getIBAValue(ecn, "FLayoutOther")==null?"":IBAUtil.getIBAValue(ecn, "FLayoutOther").toString();
			cell = row.getCell(65);
			cell.setCellValue(FLayoutOther);
			
			//EE/深圳PM   FEE
			String FEE=IBAUtil.getIBAValue(ecn, "FEE")==null?"":IBAUtil.getIBAValue(ecn, "FEE").toString();
			cell = row.getCell(66);
			cell.setCellValue(FEE);
			
			//EE/深圳PM意见    FEEOther
			String FEEOther=IBAUtil.getIBAValue(ecn, "FEEOther")==null?"":IBAUtil.getIBAValue(ecn, "FEEOther").toString();
			cell = row.getCell(67);
			cell.setCellValue(FEEOther);
			
			//ME/深圳PM   FME
			String FME=IBAUtil.getIBAValue(ecn, "FME")==null?"":IBAUtil.getIBAValue(ecn, "FME").toString();
			cell = row.getCell(68);
			cell.setCellValue(FME);
			
			//ME/深圳PM意见  FMEOther
			String FMEOther=IBAUtil.getIBAValue(ecn, "FMEOther")==null?"":IBAUtil.getIBAValue(ecn, "FMEOther").toString();
			cell = row.getCell(69);
			cell.setCellValue(FMEOther);
			
			//*******************************功能验证结果*********************end
			//*******************************良率验证结果*********************begin
			//PI/深圳车机厂   LLPI
			String LLPI=IBAUtil.getIBAValue(ecn, "LLPI")==null?"":IBAUtil.getIBAValue(ecn, "LLPI").toString();
			cell = row.getCell(70);
			cell.setCellValue(LLPI);
			
			//PI/深圳车机厂意见   LLPIOther
			String LLPIOther=IBAUtil.getIBAValue(ecn, "LLPIOther")==null?"":IBAUtil.getIBAValue(ecn, "LLPIOther").toString();
			cell = row.getCell(71);
			cell.setCellValue(LLPIOther);
			
			//Array/深圳LCM一厂   LLArray
			String LLArray=IBAUtil.getIBAValue(ecn, "LLArray")==null?"":IBAUtil.getIBAValue(ecn, "LLArray").toString();
			cell = row.getCell(72);
			cell.setCellValue(LLArray);
			
			//Array/深圳LCM一厂意见   LLArrayOther
			String LLArrayOther=IBAUtil.getIBAValue(ecn, "LLArrayOther")==null?"":IBAUtil.getIBAValue(ecn, "LLArrayOther").toString();
			cell = row.getCell(73);
			cell.setCellValue(LLArrayOther);
			
			//Cell/深圳LCM五厂    LLCell
			String LLCell=IBAUtil.getIBAValue(ecn, "LLCell")==null?"":IBAUtil.getIBAValue(ecn, "LLCell").toString();
			cell = row.getCell(74);
			cell.setCellValue(LLCell);
			
			//Cell/深圳LCM五厂意见   良率Cell深圳LCM五厂意见
			String LLCellOther=IBAUtil.getIBAValue(ecn, "LLCellOther")==null?"":IBAUtil.getIBAValue(ecn, "LLCellOther").toString();
			cell = row.getCell(75);
			cell.setCellValue(LLCellOther);
			
			//CF/深圳CSTN厂   LLCF
			String LLCF=IBAUtil.getIBAValue(ecn, "LLCF")==null?"":IBAUtil.getIBAValue(ecn, "LLCF").toString();
			cell = row.getCell(76);
			cell.setCellValue(LLCF);
			
			//CF/深圳CSTN厂意见   LLCFOther  
			String LLCFOther=IBAUtil.getIBAValue(ecn, "LLCFOther")==null?"":IBAUtil.getIBAValue(ecn, "LLCFOther").toString();
			cell = row.getCell(77);
			cell.setCellValue(LLCFOther);
			
			//Module/深圳CTP厂   LLModule
			String LLModule=IBAUtil.getIBAValue(ecn, "LLModule")==null?"":IBAUtil.getIBAValue(ecn, "LLModule").toString();
			cell = row.getCell(78);
			cell.setCellValue(LLModule);
			
			//Module/深圳CTP厂意见  LLModuleOther
			String LLModuleOther=IBAUtil.getIBAValue(ecn, "LLModuleOther")==null?"":IBAUtil.getIBAValue(ecn, "LLModuleOther").toString();
			cell = row.getCell(79);
			cell.setCellValue(LLModuleOther);
			//*******************************良率验证结果*********************end
			
			//可靠性Reliability
			String reliability=IBAUtil.getIBAValue(ecn, "Reliability")==null?"":IBAUtil.getIBAValue(ecn, "Reliability").toString();
			cell = row.getCell(80);
			cell.setCellValue(reliability);
			//客户承认Customeracknowledges
			String customeracknowledges=IBAUtil.getIBAValue(ecn, "Customeracknowledges")==null?"":IBAUtil.getIBAValue(ecn, "Customeracknowledges").toString();
			cell = row.getCell(81);
			cell.setCellValue(customeracknowledges);
			//BOM表变更&物料库存处理BomChange
			String bomChange=IBAUtil.getIBAValue(ecn, "BomChange")==null?"":IBAUtil.getIBAValue(ecn, "BomChange").toString();
			cell = row.getCell(82);
			cell.setCellValue(bomChange);
			//内部评审决议ResolutionOfInternalReview
			String resolutionOfInternalReview=IBAUtil.getIBAValue(ecn, "ResolutionOfInternalReview")==null?"":IBAUtil.getIBAValue(ecn, "ResolutionOfInternalReview").toString();
			cell = row.getCell(83);
			cell.setCellValue(resolutionOfInternalReview);
			i++;
		}
		
		
		//return hwb;
	}
	
	
	
	/**
	 * 获取项目的里程碑的变更记录,excel输出
	 * @param proj
	 * @param hwb
	 * @throws WTException
	 */
	public static void getMileStoneChangeListReport(Project2 proj,HSSFWorkbook hwb) throws WTException{
		System.out.println("getMileStoneChangeListReport");
		// 读取excel文件
		HSSFSheet sheet = hwb.getSheetAt(0);
		HSSFRow row = null;
		HSSFCell cell = null;
		int i = 0;
		Plan plan = TianmaProjectUtil.getPlan(proj);
		if (plan == null) {
			return;
		}

		WTCollection wtc = PlannableHelper.service.getAllChildren((Plannable) plan);
		Iterator itor = wtc.persistableIterator();
		// HashMap map = new HashMap();
		
		
		/******************************************************************************/
		int cellY = 0;// 列
		TreeMap postionTable=new TreeMap();//记录里程碑输出表的位置
		Hashtable mileStoneTable=new Hashtable();//记录项目有多少里程碑活动
		//Hashtable historyRecordTable=new 
		Hashtable firsttimeTable=new Hashtable();//记录第一次预估计完成时间
		Hashtable increatetimeTable=new Hashtable();//每获取到一次当前值就更新一次,记录时间会随着获取不断改变
		Hashtable postionRemaincTable=new Hashtable();//记录是否里程碑报表没有输出
		Vector vecOrder=new Vector();//里程碑名称输出的顺序
		TreeMap outTable=new TreeMap();//修改次数的
		//先将项目中所有的里程碑名称输出
		if (itor.hasNext()) {
			while (itor.hasNext()) {
				PlanActivity planActi = (PlanActivity) itor.next();
				if (planActi != null) {
					// 非里程碑 不做处理
					if (!planActi.isMilestone()) {
						continue;
					}
					// 计划根节点不做处理
					if (planActi.getLineNumber() == 0) {
						continue;
					}
					
					String activityName=planActi.getName().trim();
					long planActiID=PersistenceHelper.getObjectIdentifier(planActi).getId();
					String actiID=activityName+"|"+planActiID;//活动标示
					row = sheet.getRow(i);
					cell = row.getCell(cellY+1);
					cell.setCellValue(activityName);
					outDebugInfo("第"+i+" 行的>>>第"+(cellY+1)+" 列 "+activityName);
					postionTable.put(actiID, (cellY+1));
					mileStoneTable.put(actiID,planActi);
					postionRemaincTable.put(actiID, planActi);//获取里程碑记录,然后获取一条就删除已此表格一条，如果到最后还有记录则说明该条是没有变更的
					vecOrder.add(actiID);
					cellY++;
					
				}
		     }
		}
		i++;
		//获取有更改记录的对象
		QueryResult qr=TianmaProjectUtil.queryHistoryRecordPlanActivity(proj);
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+qr.size());
		int w=1;//记录修改次数
		if(qr!=null){
			
			while(qr.hasMoreElements()){
				Persistable pb[]=(Persistable[]) qr.nextElement();
				HistoryRecord hr=(HistoryRecord) pb[0];
				HistoryRecordLink hrl=(HistoryRecordLink) pb[1];
				PlanActivity  activity=(PlanActivity) pb[2];
				if(activity==null ||"0".equals(activity.getLineNumber())){
					continue;
				}
				
				String activityName=activity.getName()==null?"":activity.getName().trim();
				outDebugInfo("find planactivity>>>>"+activityName);
				long planActiID=PersistenceHelper.getObjectIdentifier(activity).getId();
				String actiID=activityName+"|"+planActiID;//活动标示
				
				//String esCompTimeStr= (String) vec.get(0);//初始估计完成时间
				String s2 = hr.getPersistInfo().getObjectIdentifier().getStringValue();
				System.out.println(">>>>>>"+s2);
				
                String s3 = XMLGeneratorHelper.getHistoryXML((new StringBuilder()).append("OR:").append(s2).toString());
                
                Document document = HistoryXMLHelper.parse(s3);
                String s4 = hr.getLabel();
                System.out.println(">>>>>>"+s4);
                NodeList nodelist = document.getElementsByTagName(s4);
                
                String changeTimeStr="";//获取记录时间
                if(nodelist.getLength() > 0)
                {
                    Node node = nodelist.item(0);
                    System.out.println(">>>>>>"+node.getTextContent());
                    String contentFinishTime=node.getTextContent();
                    Date finshDate=null;
                    SimpleDateFormat f = new SimpleDateFormat("yyyy/MM/dd"); // 格式化为
                    try{
                    	f.parse(contentFinishTime);
                    }
                    catch (ParseException e) {
            			SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM-dd"); // 格式化为
            			// hhmmss
            			try {
            				finshDate = f2.parse(contentFinishTime);
            			} catch (ParseException e1) {
            				// TODO Auto-generated catch block
            				e1.printStackTrace();
            			}

            		}
                    
                    changeTimeStr= WTStandardDateFormat.format(finshDate,"yyyy/MM/dd") ;
                   
                    outDebugInfo("changeTimeStr>>>"+changeTimeStr);
                }
                //判断当前活动节点是否有记录过了
                if(firsttimeTable.get(actiID)==null){
                	outDebugInfo("activityName:"+actiID+" 记录没有计算过,第一次添加");
                	firsttimeTable.put(actiID, changeTimeStr);
                	increatetimeTable.put(actiID, changeTimeStr);
                	if(postionRemaincTable.containsKey(actiID)){
                		postionRemaincTable.remove(actiID);//在剩余表中删除该条记录
                	}
                	
                }else{
                
                	Hashtable vecOut=new Hashtable();
                	increatetimeTable.remove(actiID);
                	increatetimeTable.put(actiID, changeTimeStr);
                	Hashtable out1Table=new Hashtable();//输出条目
                	//本次修改与非本次修改 在时间上加_target 与_other 区别
                	outDebugInfo("hr.getCreateTimestamp():"+hr.getCreateTimestamp());
                	
                	
                	String modifyTimeStr=WTStandardDateFormat.format(hr.getCreateTimestamp(),"yyyy/MM/dd" ,Locale.getDefault(), TimeZone.getDefault()) ;
                	System.out.println("modifyTimeStr>>>>"+modifyTimeStr);
                	
                	if("".equals(modifyTimeStr)){
                		modifyTimeStr=" ";
                	}
                	String targetModifyTime=changeTimeStr+"_target_"+modifyTimeStr;
                	outDebugInfo(targetModifyTime);
                	out1Table.put(actiID, targetModifyTime);//本次修改条目  
                	//获取不是本次修改的条目的记录
                	Iterator mileItor=mileStoneTable.keySet().iterator();
                	while(mileItor.hasNext()){
                		String mileKey=mileItor.next().toString();
                		if(!mileKey.equals(actiID)){
                			String finshTime=increatetimeTable.get(mileKey)==null?"":increatetimeTable.get(mileKey).toString();
                    		//out1Table.put(mileKey, finshTime);
                    		out1Table.put(mileKey, finshTime+"_other");//非本次修改
                		}
                		
                	}
                	
                	outTable.put(w, out1Table);
                	
                	outDebugInfo("actiID:"+actiID+" 记录意见计算过,需要更新记录值");
                	w++;
                }
				
			}
		}
		outDebugInfo("*************************获取记录完成***************");
		row = sheet.getRow(i);
		cell = row.getCell(0);
		cell.setCellValue("初始估计完成时间");
		
		outDebugInfo("第"+i+"行第0列:初始估计完成时间");
		
		//剩余的还未处理
		//初始估计完成时间输出
		
		for(int ww=0;ww<vecOrder.size();ww++){
			String actiID=vecOrder.get(ww).toString();
			outDebugInfo(actiID);
			//mileStoneTable.get(actiID);
			String finshTimeTemp=firsttimeTable.get(actiID)==null?"":firsttimeTable.get(actiID).toString();
			outDebugInfo(finshTimeTemp);
			outDebugInfo(""+"".equals(finshTimeTemp));
			outDebugInfo(""+postionRemaincTable.containsKey(actiID));
			//如果第一个时间为空且是剩余记录，说明该记录没有被修改
			if("".equals(finshTimeTemp)&&postionRemaincTable.containsKey(actiID)){
				PlanActivity actTemp=(PlanActivity) postionRemaincTable.get(actiID);
				finshTimeTemp= WTStandardDateFormat.format(actTemp.getFinishDate(),"yyyy/MM/dd") ;
			}
			
			cell = row.getCell((ww+1));
			cell.setCellValue(""+finshTimeTemp);
			outDebugInfo("第"+i+"行第"+(ww+1)+"列:"+finshTimeTemp);
		}
		
		
		i++;//行增加
		outDebugInfo("out put the line:"+i);
		Iterator iterator=outTable.keySet().iterator();
		while(iterator.hasNext()){
			Object key= iterator.next();
			Hashtable table=(Hashtable) outTable.get(key);
			outDebugInfo("key>>>>>>"+key);
			row = sheet.getRow(i);
			cell = row.getCell(0);
			String strKey="第"+key+"次更改";
			cell.setCellValue(strKey);
			//outDebugInfo(strKey);
			for(int kk=0;kk<vecOrder.size();kk++){
				String actiID=vecOrder.get(kk).toString();
				String timeTemp=table.get(actiID).toString();
				outDebugInfo(timeTemp);
				String strTemp[]=timeTemp.split("_");
				String finshTimeTemp=strTemp[0];
				
				if(timeTemp.contains("_target")){
					String modifyTime=strTemp[2];
					if("".equals(finshTimeTemp)&&postionRemaincTable.containsKey(actiID)){
						PlanActivity actTemp=(PlanActivity) postionRemaincTable.get(actiID);
						finshTimeTemp= WTStandardDateFormat.format(actTemp.getFinishDate(),"yyyy/MM/dd") ;
					}
					PlanActivity activity =(PlanActivity) mileStoneTable.get(actiID);
					//String modifyTime=WTStandardDateFormat.format(activity.getFinishDate(),"yyyy/MM/dd");
					cell = row.getCell((kk+1));
					cell.setCellValue(""+finshTimeTemp);
					//设置样式
					 HSSFCellStyle cs = hwb.createCellStyle();
					 cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
					 cs.setFillForegroundColor(new HSSFColor.LIGHT_GREEN().index); cell.setCellStyle(cs);
					 //设置备注
					 HSSFPatriarch p=sheet.createDrawingPatriarch();

					 HSSFComment comment=p.createComment(new HSSFClientAnchor(0,0,0,0,(short)3,3,(short)5,6));
					  //输入批注信息
					 comment.setString(new HSSFRichTextString(modifyTime));
					  //将批注添加到单元格对象中
					 cell.setCellComment(comment);
					
				}else {
					
					if("".equals(finshTimeTemp)&&postionRemaincTable.containsKey(actiID)){
						PlanActivity actTemp=(PlanActivity) postionRemaincTable.get(actiID);
						finshTimeTemp= WTStandardDateFormat.format(actTemp.getFinishDate(),"yyyy/MM/dd") ;
					}
					cell = row.getCell((kk+1));
					
					cell.setCellValue(""+finshTimeTemp);
				}
			}
			
			
			 i++;

		}
		
		//return hwb;
	}
}
